package org.wu.spring.db.integration.compare.infrastructure.persistence;

import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
import org.wu.framework.lazy.orm.database.lambda.stream.wrapper.LazyWrappers;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;
import org.wu.spring.db.integration.compare.domain.model.orm.compare.records.DbCompareRecords;
import org.wu.spring.db.integration.compare.infrastructure.converter.OrmCompareRecordsConverter;
import org.wu.spring.db.integration.compare.infrastructure.entity.DbCompareRecordsDO;

import org.wu.spring.db.integration.compare.domain.model.orm.compare.records.DbCompareRecordsRepository;
import org.springframework.stereotype.Repository;
import java.util.stream.Collectors;
import jakarta.annotation.Resource;

import java.util.List;

/**
 * describe Orm 操作记录 
 *
 * @author Jia wei Wu
 * @date 2024/02/28 01:02 下午
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyInfrastructurePersistence 
 **/
@Repository
public class DbCompareRecordsRepositoryImpl implements DbCompareRecordsRepository {

    @Resource
    LazyLambdaStream lazyLambdaStream;

    /**
     * describe 新增Orm 操作记录
     *
     * @param dbCompareRecords 新增Orm 操作记录
     * @return {@link Result< DbCompareRecords >} Orm 操作记录新增后领域对象
     
     * @author Jia wei Wu
     * @date 2024/02/28 01:02 下午
     **/
    @Override
    public Result<DbCompareRecords> story(DbCompareRecords dbCompareRecords) {
        DbCompareRecordsDO dbCompareRecordsDO = OrmCompareRecordsConverter.INSTANCE.fromOrmCompareRecords(dbCompareRecords);
        lazyLambdaStream.upsert(dbCompareRecordsDO);
        return ResultFactory.successOf();
    }

    /**
     * describe 批量新增Orm 操作记录
     *
     * @param dbCompareRecordsList 批量新增Orm 操作记录
     * @return {@link Result<List< DbCompareRecords >>} Orm 操作记录新增后领域对象集合
     
     * @author Jia wei Wu
     * @date 2024/02/28 01:02 下午
     **/

    @Override
    public Result<List<DbCompareRecords>> batchStory(List<DbCompareRecords> dbCompareRecordsList) {
        List<DbCompareRecordsDO> dbCompareRecordsDOList = dbCompareRecordsList.stream().map(OrmCompareRecordsConverter.INSTANCE::fromOrmCompareRecords).collect(Collectors.toList());
        lazyLambdaStream.upsert(dbCompareRecordsDOList);
        return ResultFactory.successOf();
    }

    /**
     * describe 查询单个Orm 操作记录
     *
     * @param dbCompareRecords 查询单个Orm 操作记录
     * @return {@link Result< DbCompareRecords >} Orm 操作记录领域对象
     
     * @author Jia wei Wu
     * @date 2024/02/28 01:02 下午
     **/

    @Override
    public Result<DbCompareRecords> findOne(DbCompareRecords dbCompareRecords) {
        DbCompareRecordsDO dbCompareRecordsDO = OrmCompareRecordsConverter.INSTANCE.fromOrmCompareRecords(dbCompareRecords);
        DbCompareRecords dbCompareRecordsOne = lazyLambdaStream.selectOne(LazyWrappers.lambdaWrapperBean(dbCompareRecordsDO), DbCompareRecords.class);
        return ResultFactory.successOf(dbCompareRecordsOne);
    }

    /**
     * describe 查询多个Orm 操作记录
     *
     * @param dbCompareRecords 查询多个Orm 操作记录
     * @return {@link Result<List< DbCompareRecords >>} Orm 操作记录领域对象
     
     * @author Jia wei Wu
     * @date 2024/02/28 01:02 下午
     **/

    @Override
    public Result<List<DbCompareRecords>> findList(DbCompareRecords dbCompareRecords) {
        DbCompareRecordsDO dbCompareRecordsDO = OrmCompareRecordsConverter.INSTANCE.fromOrmCompareRecords(dbCompareRecords);
        List<DbCompareRecords> dbCompareRecordsList = lazyLambdaStream.selectList(LazyWrappers.lambdaWrapperBean(dbCompareRecordsDO), DbCompareRecords.class);
        return ResultFactory.successOf(dbCompareRecordsList);
    }

    /**
     * describe 分页查询多个Orm 操作记录
     *
     * @param size 当前页数
     * @param current 当前页
     * @param dbCompareRecords 分页查询多个Orm 操作记录
     * @return {@link Result<LazyPage< DbCompareRecords >>} 分页Orm 操作记录领域对象
     
     * @author Jia wei Wu
     * @date 2024/02/28 01:02 下午
     **/

    @Override
    public Result<LazyPage<DbCompareRecords>> findPage(int size, int current, DbCompareRecords dbCompareRecords) {
        DbCompareRecordsDO dbCompareRecordsDO = OrmCompareRecordsConverter.INSTANCE.fromOrmCompareRecords(dbCompareRecords);
        LazyPage<DbCompareRecords> lazyPage = new LazyPage<>(current,size);
        LazyPage<DbCompareRecords> ormCompareRecordsLazyPage = lazyLambdaStream.selectPage(LazyWrappers.lambdaWrapperBean(dbCompareRecordsDO),lazyPage, DbCompareRecords.class);
        return ResultFactory.successOf(ormCompareRecordsLazyPage);
    }

    /**
     * describe 删除Orm 操作记录
     *
     * @param dbCompareRecords 删除Orm 操作记录
     * @return {@link Result< DbCompareRecords >} Orm 操作记录
     
     * @author Jia wei Wu
     * @date 2024/02/28 01:02 下午
     **/

    @Override
    public Result<DbCompareRecords> remove(DbCompareRecords dbCompareRecords) {
        DbCompareRecordsDO dbCompareRecordsDO = OrmCompareRecordsConverter.INSTANCE.fromOrmCompareRecords(dbCompareRecords);
        //  lazyLambdaStream.delete(LazyWrappers.lambdaWrapperBean(dbCompareRecordsDO));
        return ResultFactory.successOf();
    }

    /**
     * describe 是否存在Orm 操作记录
     *
     * @param dbCompareRecords Orm 操作记录领域对象
     * @return {@link Result<Boolean>} 是否存在 true 存在，false 不存在     
     
     * @author Jia wei Wu
     * @date 2024/02/28 01:02 下午
     **/

    @Override
    public Result<Boolean> exists(DbCompareRecords dbCompareRecords) {
        DbCompareRecordsDO dbCompareRecordsDO = OrmCompareRecordsConverter.INSTANCE.fromOrmCompareRecords(dbCompareRecords);
        Boolean exists=lazyLambdaStream.exists(LazyWrappers.lambdaWrapperBean(dbCompareRecordsDO));
        return ResultFactory.successOf(exists);
    }

}